package com.gorun;/**
 * Created by moneylee on 2019/4/19.
 */

import com.gorun.wechat.service.WechatRobotInterface;
import com.gorun.wechat.service.impl.WechatRobotImpl;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.stereotype.Component;

/**
 * @className: WeChatStart
 * @Description: 启动springboot后执行
 * @Author moneylee
 * @Date 2019/4/19 下午3:33
 * @Version 1.0
 **/

@Component
@Slf4j
public class WeChatStart {

    /**
    * 执行微信初始化任务
    */
    public void start() throws Exception {

        WechatRobotImpl wechatRobot = WechatRobotImpl.getInstance();
        String uuid = wechatRobot.getUUID();
        wechatRobot.showQR(uuid);

        while(!wechatRobot.loginState().equals("200")) {
            Thread.sleep(2000);
        }

        if (!wechatRobot.login()) {
            log.info("[微信登录失败]");
            return;
        }

        log.info("[微信登录成功]");

        if(!wechatRobot.initWeChat()){
            log.info("[*] 微信初始化失败");
            return;
        }

        log.info("[*] 微信初始化成功");


        if(!wechatRobot.wxStatusNotify()){
            log.info("[*] 开启状态通知失败");
            return;
        }
        log.info("[*] 开启状态通知成功");

        if(!wechatRobot.loadContact()){
            log.info("[*] 获取联系人失败");
            return;
        }

        log.info("[*] 获取联系人成功");
        log.info("[*] 共有" + wechatRobot.ContactList.size() + "位联系人");
        log.info("[*] 联系人详情" + wechatRobot.ContactList);

        // 监听消息
        wechatRobot.syncMsg();

        //定时任务
//        cronTrigger();

    }


}
